Menu = {}
Menu.__index = Menu
 
function Menu.new()
    local instance = {

    }
    
    setmetatable(instance, Menu)
    return instance
end

function showMainMenu()
  
  tutRecruit1 = false
  tutRecruit2 = false
  
  tutTapIcon1 = false
  tutTapIcon2 = false
  
  tutTapMove1 = false
  tutTapMove2 = false
  
  tutEnd1 = false
  tutEnd2 = false
  
  currentTurn = 1
  isFogOn = false
  if pl1 ~= nil then
    pl1:setGold(0)
  end
  if pl2 ~= nil then
    pl2:setGold(0)
  end
  
  renderLayerTable[2] = nil  
  renderLayerTable[3] = nil
  renderLayerTable[4] = nil
  unitHealthBoxRenderTable = {}
  
  propToTileObject = {}
  
  isGameLoopRunning = false
  currentScreen = typesOfScreens["mainmenu"]
  MainLayer:clear()
  MainLayer:setPartition(mainMenuPartition)
  camera:setLoc(0, 0)
  
  local widthLocation = (baseScreenWidth / 2) -100
  local heightLocation = -(baseScreenHeight / 2) + 100
  
  local backgroundSprite = MOAIGfxQuad2D.new()
  backgroundSprite:setTexture("resources/graphics/menu/background_welcome.png")
  backgroundSprite:setRect(-384, -370, 384, 320)

  local background = MOAIProp2D.new()
  background:setDeck(backgroundSprite)
  background:setLoc(384, -320)
  
  local titleSprite = MOAIGfxQuad2D.new()
  titleSprite:setTexture("resources/graphics/menu/title.png")
  titleSprite:setRect(0, -62, 421, 0)

  local title = MOAIProp2D.new()
  title:setDeck(titleSprite)
  title:setLoc((widthLocation / 2) + 20, (heightLocation / 2))
  
  local logoWelcome = MOAIGfxQuad2D.new()
  logoWelcome:setTexture("resources/graphics/menu/logo_welcome.png")
  logoWelcome:setRect(-93, -93, 80, 93)

  local logo = MOAIProp2D.new()
  logo:setDeck(logoWelcome)
  logo:setLoc(widthLocation + 100, heightLocation / 2 - 180)
  
  local newGame = MOAIGfxQuad2D.new()
  newGame:setTexture("resources/graphics/menu/new_game.png")
  newGame:setRect(-117, -22, 117, 22)

  local start = MOAIProp2D.new()
  start:setDeck(newGame)
  start:setLoc(widthLocation + 100, heightLocation / 2 - 325)
  
  local guideProp = MOAIGfxQuad2D.new()
  guideProp:setTexture("resources/graphics/menu/guide_btn.png")
  guideProp:setRect(-117, -22, 117, 22)

  local guide = MOAIProp2D.new()
  guide:setDeck(guideProp)
  guide:setLoc(widthLocation + 100, heightLocation / 2 - 425)
  
  mainMenuLinks[start] = "start"
  mainMenuLinks[guide] = "guide"
  
  MainLayer:insertProp(background)
  MainLayer:insertProp(title)
  MainLayer:insertProp(start)
  MainLayer:insertProp(guide)
  MainLayer:insertProp(logo)
  
  if audioTurnedOn == false then
    audio:playMenuAudio()
  end
end

function showChooseLevel()
  currentScreen = typesOfScreens["chooselevel"]
  
  MainLayer:clear()
  MainLayer:setPartition(chooseLevelPartition)
  
  local backgroundSprite = MOAIGfxQuad2D.new()
  backgroundSprite:setTexture("resources/graphics/menu/background_welcome.png")
  backgroundSprite:setRect(-384, -370, 384, 320)
  
  local backButtonSprite = MOAIGfxQuad2D.new()
  backButtonSprite:setTexture("resources/graphics/menu/backbutton.png")
  backButtonSprite:setRect(-60, -60, 30, 30)
  
  backButtonProp = MOAIProp2D.new()
  backButtonProp:setDeck(backButtonSprite)
  backButtonProp:setLoc(75, -(baseScreenHeight * 0.87)) 

  local background = MOAIProp2D.new()
  background:setDeck(backgroundSprite)
  background:setLoc(384, -320)
  
  local levelOneSprite = MOAIGfxQuad2D.new()
  levelOneSprite:setTexture("resources/graphics/menu/level1.png")
  levelOneSprite:setRect(-128, -128, 128, 128)

  local levelOne = MOAIProp2D.new()
  levelOne:setDeck(levelOneSprite)
  levelOne:setLoc(200, -(baseScreenHeight / 2) + 256)
  
  local levelTwoSprite = MOAIGfxQuad2D.new()
  levelTwoSprite:setTexture("resources/graphics/menu/level2.png")
  levelTwoSprite:setRect(-128, -128, 128, 128)
  
  local levelTwo = MOAIProp2D.new()
  levelTwo:setDeck(levelTwoSprite)
  levelTwo:setLoc(500, -(baseScreenHeight / 2) + 256)

  local levelThreeSprite = MOAIGfxQuad2D.new()
  levelThreeSprite:setTexture("resources/graphics/menu/level3.png")
  levelThreeSprite:setRect(-128, -128, 128, 128)

  local levelThree = MOAIProp2D.new()
  levelThree:setDeck(levelThreeSprite)
  levelThree:setLoc(200, -(baseScreenHeight / 2)  + 80)
  
  local levelFourSprite = MOAIGfxQuad2D.new()
  levelFourSprite:setTexture("resources/graphics/menu/level4.png")
  levelFourSprite:setRect(-128, -128, 128, 128)

  local levelFour = MOAIProp2D.new()
  levelFour:setDeck(levelFourSprite)
  levelFour:setLoc(500, -(baseScreenHeight / 2) + 80)
  
  local levelFiveSprite = MOAIGfxQuad2D.new()
  levelFiveSprite:setTexture("resources/graphics/menu/level5.png")
  levelFiveSprite:setRect(-128, -128, 128, 128)

  local levelFive = MOAIProp2D.new()
  levelFive:setDeck(levelFiveSprite)
  levelFive:setLoc(200, -(baseScreenHeight / 2) - 100)
  
  local levelSixSprite = MOAIGfxQuad2D.new()
  levelSixSprite:setTexture("resources/graphics/menu/level6.png")
  levelSixSprite:setRect(-128, -128, 128, 128)

  local levelSix = MOAIProp2D.new()
  levelSix:setDeck(levelSixSprite)
  levelSix:setLoc(500, -(baseScreenHeight / 2) - 100)
  
  chooseLevelLinks[levelOne] = 1
  chooseLevelLinks[levelTwo] = 2
  chooseLevelLinks[levelThree] = 3
  chooseLevelLinks[levelFour] = 4
  chooseLevelLinks[levelFive] = 5
  chooseLevelLinks[levelSix] = 6
  
  MainLayer:insertProp(background)
  MainLayer:insertProp(levelOne)
  MainLayer:insertProp(levelTwo)
  MainLayer:insertProp(levelThree)
  MainLayer:insertProp(levelFour)
  MainLayer:insertProp(levelFive)
  MainLayer:insertProp(levelSix)
  MainLayer:insertProp(backButtonProp)
end

function showGuide()
  currentScreen = typesOfScreens["guide"]
  
  MainLayer:clear()
  MainLayer:setPartition(guidePartition)
  
  local backgroundSprite = MOAIGfxQuad2D.new()
  backgroundSprite:setTexture("resources/graphics/menu/background_welcome.png")
  backgroundSprite:setRect(-384, -370, 384, 320)

  local background = MOAIProp2D.new()
  background:setDeck(backgroundSprite)
  background:setLoc(384, -320)
  
  local backButtonSprite = MOAIGfxQuad2D.new()
  backButtonSprite:setTexture("resources/graphics/menu/backbutton.png")
  backButtonSprite:setRect(-60, -60, 30, 30)
  
  backButtonProp = MOAIProp2D.new()
  backButtonProp:setDeck(backButtonSprite)
  backButtonProp:setLoc(75, -(baseScreenHeight  - 75)) 
  
  local forwardButtonSprite = MOAIGfxQuad2D.new()
  forwardButtonSprite:setTexture("resources/graphics/menu/forwardbutton.png")
  forwardButtonSprite:setRect(-60, -60, 30, 30)
  
  forwardButtonProp = MOAIProp2D.new()
  forwardButtonProp:setDeck(forwardButtonSprite)
  forwardButtonProp:setLoc(baseScreenWidth - 50, -(baseScreenHeight - 75))
  
  local unitGuide = MOAIGfxQuad2D.new()
  unitGuide:setTexture("resources/graphics/menu/unitguide.png")
  unitGuide:setRect(-400, -340, 230, 230)

  unitGuideProp = MOAIProp2D.new()
  unitGuideProp:setDeck(unitGuide)
  unitGuideProp:setLoc((baseScreenWidth / 2) + 80, -240)
  
  local tileGuide = MOAIGfxQuad2D.new()
  tileGuide:setTexture("resources/graphics/menu/tilesguide.png")
  tileGuide:setRect(-400, -340, 230, 230)

  tileGuideProp = MOAIProp2D.new()
  tileGuideProp:setDeck(tileGuide)
  tileGuideProp:setLoc((baseScreenWidth / 2) + 80, -240)
  tileGuideProp:setVisible(false)
  
  local heroGuide = MOAIGfxQuad2D.new()
  heroGuide:setTexture("resources/graphics/menu/capturezoneguide.png")
  heroGuide:setRect(-400, -340, 230, 230)

  heroGuideProp = MOAIProp2D.new()
  heroGuideProp:setDeck(heroGuide)
  heroGuideProp:setLoc((baseScreenWidth / 2) + 80, -240)
  heroGuideProp:setVisible(false)
  
  MainLayer:insertProp(background)
  MainLayer:insertProp(backButtonProp)
  MainLayer:insertProp(forwardButtonProp)
  MainLayer:insertProp(unitGuideProp)
  MainLayer:insertProp(tileGuideProp)
  MainLayer:insertProp(heroGuideProp)
end

 return Menu